<template>
	<view class="page today">
		<view class="category-box">
			<view v-if="goodsList.length>0" class="list">
				<template v-for="(goods, g) in goodsList">
					<view @click="viewPage(goods.id)" class="item" :key="g">
						<u-image :src="goods.image" width="340" height="340" border-radius="16" mode="widthFix">
						</u-image>
						<view class="info-box">
							<view class="name">{{goods.name}}</view>
							<view class="price">
								<text class="unit">¥ </text>
								<text class="money">{{goods.price}}</text>
							</view>
						</view>
					</view>
				</template>
			</view>
			<view v-else class="empty-box">
				<u-empty mode="list"></u-empty>
			</view>
		</view>

		<!-- 提示信息 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				queryParams: {
					page: 1,
					limit: 10,
					where: {
						scene: 0
					}
				},
				goodsList: [],

			}
		},
		onLoad(options) {
			this.queryParams.where.scene = options.type
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			viewPage(ids) {
				uni.navigateTo({
					url:'/pages/newPage/shoopDetails?id='+ids
				})
			},
			getList() {
				this.$net.req('/product/getLists', this.queryParams).then(res => {
					if (res.code === 200) {
						uni.setNavigationBarTitle({
							title: res.msg || ''
						});
						if (this.queryParams.page === 1) {
							this.goodsList = res.data.list
						} else if (res.data.list.length > 0) {
							this.goodsList = this.goodsList.concat(res.data.list)
						}

						if (res.data.list.length > 0) {
							++this.queryParams.page
						} else if (this.queryParams.page > 1) {
							this.$refs.uToast.show({
								title: '没有更多数据了！',
								type: 'info'
							})
						}
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.page.today {
		padding: 24rpx;
		background: #292C2D;
		.category-box {
			width: 100%;

			.list {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				justify-content: space-between;
				width: 702rpx;

				.item {
					width: 340rpx;
					height: 482rpx;
					background: #F6F6F6;
					border-radius: 16rpx;
					margin-bottom: 24rpx;

					.info-box {
						padding: 20rpx;
						// background: #000000;
						.name {
							height: 42rpx;
							font-size: 32rpx;
							color: #000000;
							font-weight: bold;
							line-height: 42rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 2;
							-webkit-box-orient: vertical;
						}

						.price {
							height: 40rpx;
							font-size: 32rpx;
							font-weight: bold;
							color: #DFC791;
							line-height: 40rpx;
							margin-top: 20rpx;

							.unit {
								font-size: 24rpx;
								margin-right: 10rpx;
							}
						}
					}
				}
			}

			.empty-box {
				min-height: 60vh;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>
